<?php
require_once('../include_db.php');
require_once('../constants.php');

$db = new db();
// 从请求中获取s参数 手机号码
$phone_number = str_replace(" ","",$_GET[PARAM_PHONE_NUMBER]);
//$phone_number = $_GET[PARAM_PHONE_NUMBER];
//echo 'phone_number = ' . $phone_number . NEWLINE;

$_id = 0;
$sql = "INSERT INTO pTableUserInfo(pPhoneNumber, pRegDate, pLastLoginDate, 
			pLoginCount, pIfSelfReg) values(?, ?, ?, ?, ?)";
//echo 'sql = ' . $sql . NEWLINE;
if ($stmt = $db->prepare($sql)) {
	//echo 'stmt not null' . NEWLINE;
	$stmt->bind_param('sssii', $phone_number, $reg_date, $last_login_date, $login_count, $if_self_reg);
	//$phone_number = "13777743511";
	$reg_date = date("Y-m-d H:i:s");
	$last_login_date = date("Y-m-d H:i:s");
	$login_count = 1;
	$if_self_reg = 1;	// 1 - 表示是自己注册， 0 - 表示非自己注册
	
	$stmt->execute();
	$_id = $db->conn->insert_id;
	$stmt->close();
	//echo 'insert into success' . NEWLINE;
	/*$sql = "SELECT _id FROM pTableUserInfo WHERE pPhoneNumber = '" . $phone_number . "'";
	if ($result = $db->query($sql)) {
		$row = $result->fetch_assoc();
		//echo '_id = ' . $row['_id'] . NEWLINE;
		$result->close();
		$_id = $row['_id'];
	}*/
	$db->close();
}

$mem = create_mem_conn();
$mem->set($phone_number, $_id, false, 0);
//echo 'from mem, phone_number = ' . $mem->get($_id) . NEWLINE;
echo $_id;
?>